package my.pack.tm;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MemoryActivity extends Activity {
	
	Button start, exit, about, instructions;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        start = new Button(this);
        exit = new Button(this);
        about = new Button(this);
        instructions = new Button(this);
        start = (Button)findViewById(R.id.startB);
        about = (Button)findViewById(R.id.aboutB);
        instructions = (Button)findViewById(R.id.instrB);
        exit = (Button)findViewById(R.id.exitB);
        
        start.setOnClickListener(new View.OnClickListener() { 
			
			public void onClick(View v) {
				Intent intent=new Intent(MemoryActivity.this, ChooseLvl.class);
				startActivityForResult(intent, 0);  //start another activity, with request code 0
				
			}
		});
        
        about.setOnClickListener(new View.OnClickListener() {  //when the user presses the button AddCity 
			
			public void onClick(View v) {
				Intent intent=new Intent(MemoryActivity.this, About.class); 
				startActivityForResult(intent, 1);  //start another activity, with request code 1
			}
		});
        instructions.setOnClickListener(new View.OnClickListener() {  
			
			public void onClick(View v) {
				Intent intent=new Intent(MemoryActivity.this, Instructions.class); 
				startActivityForResult(intent, 4);  //start another activity, with request code 4
			}
		});
        exit.setOnClickListener(new View.OnClickListener() {  //when the user presses the button Exit
			
			public void onClick(View v) {
				AlertDialog.Builder builder = new AlertDialog.Builder(MemoryActivity.this);  //build an alert dialog which asks for his confirmation 
				builder.setMessage("Are you sure you want to exit?")
				       .setCancelable(false)
				       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
				           public void onClick(DialogInterface dialog, int id) { //if the users chooses to continue the action finish the activity
				                MemoryActivity.this.finish();
				           }
				       })
				       .setNegativeButton("No", new DialogInterface.OnClickListener() {
				           public void onClick(DialogInterface dialog, int id) {      //else return
				                dialog.cancel();
				           }
				       });
				AlertDialog alert = builder.create();
			
				alert.show ();        //display the dialog
				
			}
		});

    	}
}
